import { computed, ref } from "vue";

// 类型 start入职 end离职
type JobDatePickerType = "start" | "end";

export function useSkillDatePicker() {
	const selected = ref(Date.now());
	const pickerType = ref<JobDatePickerType>("start");
	const show = ref(false);

	const open = (type: JobDatePickerType, value: string) => {
		if (value) {
			selected.value = new Date(value).getTime();
		} else {
			selected.value = Date.now();
		}

		pickerType.value = type;
		show.value = true;
	};

	const close = () => {
		show.value = false;
	};

	return {
		selected,
		pickerType,
		isStartPicker: computed(() => pickerType.value === "start"),
		isEndPicker: computed(() => pickerType.value === "end"),
		show,
		open,
		close,
	};
}
